 package com.nanuminc.market.today;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.nanuminc.market.R;
import com.nanuminc.market.today.TodayLocationCity_ngoc.ListViewItemClickListener;

     	public class TodayLocationDistric_ngoc extends Activity {
     	  
     	  private ListView mLv_DistrictList ;
       	  private TextView location_info ;
     	  private ArrayAdapter<String> listAdapter ;
     	  private int city_position;
     	  private String city_name;
     	  String[] loc;     	  
     	  
     	  /** Called when the activity is first created. */
     	  @Override
     	  public void onCreate(Bundle savedInstanceState) {
     	    super.onCreate(savedInstanceState);
    		requestWindowFeature(Window.FEATURE_NO_TITLE);
     	    setContentView(R.layout.location_district_ngoc);

     	   //Intent Data Loading 
     	   Intent i = getIntent();   // getting attached intent data
           city_position = i.getIntExtra("city_position",0);
           city_name = i.getStringExtra("city_name");
           
     	    
     	    
     	    
     	    mLv_DistrictList = (ListView) findViewById(android.R.id.list); 
         	location_info = (TextView) findViewById(R.id.loc2Tv);  //Textview to display Location sellected.
         	location_info.setText(city_name);
    
            if (city_position == 0){
	     	    loc = getResources().getStringArray(R.array.Seoul_info_ngoc);  //without this, the content can not be viewed on screen
	     	    
     	    }
            else if (city_position == 1){
	     	    loc = getResources().getStringArray(R.array.Busan_info_ngoc);  //without this, the content can not be viewed on screen
     	    }else
     	    {
	     	    loc = getResources().getStringArray(R.array.category);  //without this, the content can not be viewed on screen
     	    };	
     	    
     	   listAdapter = new MyArrayAdapter(this);
     	   mLv_DistrictList.setAdapter( listAdapter );     	        	        	  
     	   mLv_DistrictList.setOnItemClickListener( new ListViewItemClickListener() );
     	   //Button Intent Interface
     	   /**
     	   mLv_DistrictList.setOnItemClickListener(new OnItemClickListener(){
     		  public void onItemClick(AdapterView<?> parent, View view, 
      	              int position, long id) { 
     			  		String district_name =  ((TextView) view).getText().toString();
     			  		location_info.setText(city_name + "->" + district_name);
      	        	  //	Toast.makeText(parent.getContext(), "hello" + position, Toast.LENGTH_LONG).show();    	  
      	          	  }    		   
     	   });
     	   
     	   Button btn_comfirm = (Button) findViewById(R.id.confirmBnt);
     	   btn_comfirm.setOnClickListener(new OnClickListener(){
     		  public void onClick(View arg0){		  
    			  Intent browserIntent = 
                          new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
			    startActivity(browserIntent);

   	        	  //	Toast.makeText(parent.getContext(), "hello" + position, Toast.LENGTH_LONG).show();     			   
     		  }   		   
     	   });**/  
     	   
     	  }
     	  
     	  
     	  
     	  
     	  
     	 private class ListViewItemClickListener implements AdapterView.OnItemClickListener{
 	        @Override
 	        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {	        		        
 	        	Intent i = new Intent(getApplicationContext(), TodayLocationDistric_ngoc.class);
 				i.putExtra("district_name",  loc[position].toString());
 				i.putExtra("city_name", city_name);
 				i.putExtra("city_position", position);
 				startActivity(i);
 	        }        
 	    }
     	  
     	  
     	  
     	 class MyArrayAdapter extends ArrayAdapter<String>{
      		Context context;
      		TextView district;     	     		
      		MyArrayAdapter(Context context){
      			super(context, R.layout.list_view_loc, loc);
      			this.context = context;
      		}     		
      		public View getView(int position, View convertView, ViewGroup parent){
      			View row = convertView;     			     			
      			if (row == null) {
      				LayoutInflater inflater = ((Activity)context).getLayoutInflater();
      				row= (View)inflater.inflate(R.layout.list_view_loc, null);}     			
      			district = (TextView)row.findViewById(R.id.city_name);
      			district.setText(loc[position]);     			
      			return row;
      		}     		
      	}			
      
     	  
     	  
     	  
     	  
     	}